-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove panic from crdt.RGATreeList #596
Remove panic from crdt.RGATreeList #596
Conversation
Codecov Report
@@ Coverage Diff @@
## main #596 +/- ##
==========================================
+ Coverage 51.11% 51.47% +0.36%
==========================================
Files 66 66
Lines 7008 6962 -46
==========================================
+ Hits 3582 3584 +2
+ Misses 2952 2904 -48
Partials 474 474
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
Overall it looks good. I left a minor comment related to style.
And if possible, it would be nice to add related test codes as well.
@@ -214,7 +214,9 @@ func (p *Array) insertAfterInternal( | |||
ticket, | |||
)) | |||
|
|||
p.InsertAfter(prevCreatedAt, value) | |||
if err = p.InsertAfter(prevCreatedAt, value); err != nil { | |||
panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you tell me why panic is called?
I think it's safer to handle errors using errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, are you going to phase it out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it is okay to call panic in json
according to #497 (comment).
It would be great to change the above logic to handle errors if possible.
I guess one of possible errors can be an error that occurs because of a failure of finding a node for the given createdAt.
func (a *RGATreeList) findNextBeforeExecutedAt(
createdAt *time.Ticket,
executedAt *time.Ticket,
) (*RGATreeListNode, error) {
node, ok := a.nodeMapByCreatedAt[createdAt.Key()]
if !ok {
return nil, fmt.Errorf("fail to find the given createdAt: %s", createdAt.Key())
}
...
}
Would you mind giving me some guides or examples to safely handle errors like the above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left one more minor comment.
What this PR does / why we need it:
This removes panic in
crdt/rga_tree_list
that should be avoided in production.Which issue(s) this PR fixes:
Related to #497
Special notes for your reviewer:
I guess it would be good to add some test cases for errors.
Would you mind giving me some comments about this?
I'm just planning to add tests for a basic success and the errors included in this pr.
Does this PR introduce a user-facing change?:
Additional documentation
Checklist: